package com.wwz.leetcode;

import org.junit.Test;

/**
 * 数字翻转
 */
public class LeetCode7 {

    /*
    输入：x = 123
    输出：321
     */
    public int reverse(int x) {
        int n = 0;
        while (x != 0) {
            n = n * 10 + x % 10;
            x = x / 10;
        }
        return (int) n == n ? (int) n : 0;

    }

    @Test
    public void test() {
        System.out.println(reverse(-123));
    }
}
